Object name/de

Einleitung

Alle Objekte im Programm haben einen Objektnamen, der sie in einem bestimmten Dokument eindeutig identifiziert.

Diese Informationen gelten für alle Objekte, die von einem Dokumentobjekt (App DocumentObject, d.h. der Klasse App::DocumentObject)abgeleitet sind, die im Wesentlichen alle Objekte umfasst, die in einem Dokument erstellt werden können.

Namen

Namen besitzen verschiedene Eigenschaften:

Zusammengefasst stellt der Name einen eindeutigen Identifikator (unique identifier, UID) eines Objekts dar. Da ein eindeutiger Name sehr eingeschränkt ist, besitzen Objekte auch noch die Eigenschaft Label, die ermöglicht, das Objekt "umzubenennen", also eine besser beschreibende Benennung hinzuzufügen. Der interne Name bleibt tatsächlich unverändert, aber die vom Benutzer editierbare Benennung Label kann in den meisten Fällen an Stelle des Namens verwendet werden. In der üblichen Verwendung im Programm bezieht sich "umbenennen" auf das Label (Benennung) und nicht auf den wirklichen Namen des Objekts.

Benennungen

There are various properties for Labels:

<<Custom Label With Spaces>>.Height
<<Label may use UTF8 characters>>.Width

Label2

It is a simple string that can contain arbitrary text, and therefore can be used for documenting (describing with more detail) the created object.

Skripten

Siehe auch: FreeCAD Grundlagen Skripten und Skriptgenerierte Objekte.

Any object in the software is internally created with the addObject() method of the document. The majority of 2D and 3D objects that the user will see in the 3D view are derived from a Part Feature. In the following example, the object created is a Part Box.

import FreeCAD as App

doc = App.newDocument()
obj = doc.addObject("Part::Box", "Name")
obj.Label = "Custom label"

Name

The addObject function has two basic string arguments.

Benennung

The Label is a property of the created object and can be changed to a more meaningful text.

Ein Objekt mit Namen oder Benennung aufrufen

All objects in a document are data attributes of the corresponding Document object. The attribute's name correspond to the internal Name of the object.

import FreeCAD as App

obj1 = App.ActiveDocument.Box
obj2 = App.ActiveDocument.Box001
obj3 = App.ActiveDocument.Box002

This is equivalent to using the getObject method of the Document.

import FreeCAD as App

obj1 = App.ActiveDocument.getObject('Box')
obj2 = App.ActiveDocument.getObject('Box001')
obj3 = App.ActiveDocument.getObject('Box002')

However, it is also possible to get the object by the more descriptive Label.

import FreeCAD as App

obj1 = App.ActiveDocument.getObjectsByLabel("Concrete wall")[0]
obj2 = App.ActiveDocument.getObjectsByLabel("Custom parallelepiped")[0]
obj3 = App.ActiveDocument.getObjectsByLabel("Some special name for this cube__002")[0]

Given that the Label is in general not unique, the getObjectsByLabel method returns a list with all objects found with that Label. However, if the Label is unique in the document then the first element in that list should be the desired object.